﻿using System.Collections.Generic;
using AmazeUI.bll.Open.Weixin;
using AmazeUI.bll.Open.WeixinPay;

namespace AmazeUI.bll.Open.OpenModel
{
    public class  WxAddressConfig:WxConfig
    {
        public string addrSign { get; private set; }
        public string accessToken { get; set; }
        public string Url { get; set; }
        /// <summary>
        /// 签名方式
        /// </summary>
        public string signType { get; private set; }

        public WxAddressConfig(Wx getWx, string wxSignature, string url, string accessToken)
            : base(getWx, wxSignature)
        {
            this.scope = "jsapi_address";
            this.signType = "sha1";
            this.Url = url;
            this.accessToken = accessToken;
            Sign(url, accessToken);
        }

        public void Sign(string url, string accessToken)
        {
            //var data = string.Format("accesstoken={0}&appid={1}&noncestr={2}&timestamp={3}&url={4}&key={5}", this.appId, this.nonceStr, this.package, "MD5", this.timestamp, WxPackage.Key);
            //this.paySign = WebCommon.Encryption.Md532(data).ToUpper();

            var sd = new SortedDictionary<string, string>();
            sd.Add("appid", this.appId);
            sd.Add("timestamp", this.timestamp);
            sd.Add("noncestr", this.nonceStr);
            sd.Add("url", url);
            sd.Add("accesstoken", accessToken);
            var ob = WebCommon.StringCommand.Static.GetOrderBy(sd);
            this.addrSign = WebCommon.Encryption.Sha1(ob);
        }

        /// <summary>
        /// scope
        /// </summary>
        public string scope { get;private set ; }
    }
}